let regPhone = /^1[7538]\d{9}$/;
let loginFlagPhone;
let loginFlagPwd;
$("#_loginId").blur(function() {
	if (regPhone.test($("#_loginId").val())){
		loginFlagPhone = true;
		console.log(loginFlagPhone);
	} else {
		$(this).next().css({
			display: "block",
			color:"red"
		})
		$(this).css({
			border: "1px solid #d51b51"
		})
	}
})
$("#_loginId").focus(function() {
	$(this).next().css({
		display: "none",
	})
	$(this).css({
		border: "1px solid #dadada"
	})
})
$("#_loginPwd").blur(function() {
	console.log($("#_loginPwd").val());
	if ($("#_loginPwd").val() == "") {
		$(this).next().css({
			display: "block",
		})
		$(this).css({
			border: "1px solid #d51b51"
		})
	} else {
		loginFlagPwd = true;
		console.log(loginFlagPwd);
	}
})
$("#_loginPwd").focus(function() {
	$(this).next().css({
		display: "none",
	})
	$(this).css({
		border: "1px solid #dadada"
	})
})



//登录向数据库发送数据 看是否请求成功
$("#input1").click(function() {
		console.log(123);
			let _loginId = $('#_loginId').val();
			let _loginPwd = $('#_loginPwd').val();
			if (loginFlagPhone && loginFlagPwd) {
				console.log("登录前端验证成功可发送数据");
				$.ajax({
					url: "../php/login.php",
					type: "post",
					data: "loginId=" + _loginId + "&loginPwd=" + _loginPwd,
					success: function(resText) {
						if (resText == 1) {
							let login1 = localStorage.getItem('login1');
							login1 = 1;
							localStorage.setItem('login1', login1);
							console.log(resText)
							// location.href="index.html";
							$(window).attr('location', '../html/index.html');
						} else if (resText == 2) {
							let login1 = localStorage.getItem('login1');
							 login1=0;
							 localStorage.setItem('login1', login1);
							alert("用户名或密码错误")
						} else if (resText == 0) {
							alert("用户名或密码错误")
						}
					},
				})
			}
		// $(window).attr('location', '../html/index.html');
		})


